/*
* @Author: dengjiayao
* @Date:   2017-08-29 14:09:25
* @Last Modified by:   dengjiayao
* @Last Modified time: 2017-08-30 17:13:32
*/
import { modal } from 'vue-strap'
import { showMsg, addSelectedBeta } from '../../../vuex/action'

export default {
  name: 'editor-chosen-config',
  data() {
    return {
      showModal: false,
      form: {
        market: '0',
        betaId: ''
      }
    }
  },
  components: {
    'vue-modal': modal
  },
  vuex: {
    actions: {
      xShowMsg: showMsg,
      xAdd: addSelectedBeta
    }
  },
  methods: {
    valid() {
      let fields = ['market', 'betaId']
      for (let k of fields) {
        let v = this.form[k] + ''
        if (v.length === 0) {
          return Promise.reject({
            error_msg: '*标识的均为必填项'
          })
        }
      }
      return Promise.resolve()
    },
    submit() {
      this.valid()
        .then(() => {
          return this.xAdd(this.form)
        })
        .then(() => {
          this.showModal = false
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    }
  }
}
